#pragma once

#include <queue>
#include <vector>

namespace jianzhi_040
{

class Solution
{
public:
    std::vector<int> getLeastNumbers(std::vector<int>& arr, int k)
    {
        if (k == 0)
            return { };

        std::priority_queue<int> k_max;
        for (auto val : arr) {
            if ((int)k_max.size() < k) {
                k_max.push(val);
            } else if (val < k_max.top()) {
                k_max.pop();
                k_max.push(val);
            }
        }
        arr.clear();
        while (!k_max.empty()) {
            arr.push_back(k_max.top());
            k_max.pop();
        }
        return arr;
    }
};

}  /* namespace jianzhi_040 */
